<html>
<head><meta charset="utf-8"><title>Structural Search Replace · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html">Structural Search Replace</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="180870102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/180870102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#180870102">(Nov 15 2019 at 20:46)</a>:</h4>
<p>I've almost nerdsnipped myself with this, but decided to write up an issue with mentoring instructions in the end: <a href="https://github.com/rust-analyzer/rust-analyzer/issues/2267" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/issues/2267">https://github.com/rust-analyzer/rust-analyzer/issues/2267</a> :)</p>



<a name="180902153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/180902153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> csmoe <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#180902153">(Nov 16 2019 at 07:55)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> <a href="https://github.com/google/rerast" target="_blank" title="https://github.com/google/rerast">https://github.com/google/rerast</a> may help here, I'm transforming generated code with it these days.</p>



<a name="180904298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/180904298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#180904298">(Nov 16 2019 at 09:07)</a>:</h4>
<p><span class="user-mention" data-user-id="116773">@csmoe</span> the idea is exactly to build rerast-like thin, but using rust-analyzer's types, which I believe I fundamentally more suitable for this kind of things in the limit (ie, when we finishing implementing all the things we yet have to add...)</p>



<a name="181240344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181240344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Felix Kohlgrüber <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181240344">(Nov 20 2019 at 19:28)</a>:</h4>
<p>How can I parse a String into an expr syntax tree node? And also, should ssr be performed on the concrete or abstract syntax tree?</p>



<a name="181240528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181240528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181240528">(Nov 20 2019 at 19:30)</a>:</h4>
<p><span class="user-mention" data-user-id="222148">@Felix Kohlgrüber</span> <code>SourceFile::parse</code> in ra_syntax defines parsing of files</p>



<a name="181240596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181240596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181240596">(Nov 20 2019 at 19:31)</a>:</h4>
<p>I think a similar method could be defined for <code>ast::Expr</code>, but you'll need <code>parse_fragment</code> function as an entry point</p>



<a name="181240632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181240632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181240632">(Nov 20 2019 at 19:31)</a>:</h4>
<p>We don't have traditional AST (what is called <code>ast</code> is, in fact, a typed concrete syntax tree)</p>



<a name="181240734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181240734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181240734">(Nov 20 2019 at 19:32)</a>:</h4>
<p>So I think it makes sense to run ssr on concrete syntax tree, with maybe some hacks for more abstract comparison (like, not taking the order of fields into account, etc)</p>



<a name="181240774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181240774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181240774">(Nov 20 2019 at 19:32)</a>:</h4>
<p>One more interesting bit is that, because <em>replace</em> bit has to happen at the CST level, you sort-of need to run the search on the CST as well</p>



<a name="181240946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181240946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Felix Kohlgrüber <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181240946">(Nov 20 2019 at 19:34)</a>:</h4>
<p>Ok thx, got it!</p>



<a name="181241221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181241221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181241221">(Nov 20 2019 at 19:37)</a>:</h4>
<p><span class="user-mention" data-user-id="222148">@Felix Kohlgrüber</span> actually, I thik you can also use <code>make::expr_from_string</code> -- it's hacky, but works</p>



<a name="181241327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181241327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181241327">(Nov 20 2019 at 19:38)</a>:</h4>
<p><code>expr_from_text</code> that is</p>



<a name="181241504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181241504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Felix Kohlgrüber <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181241504">(Nov 20 2019 at 19:40)</a>:</h4>
<p>ah ok, that should work. Thanks!</p>



<a name="181241852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181241852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Felix Kohlgrüber <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181241852">(Nov 20 2019 at 19:44)</a>:</h4>
<p>@matklad In the issue description, you wrote that writing a custom parser for the patterns might be better than using regex. Could you explain why you think so?</p>



<a name="181241880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181241880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Felix Kohlgrüber <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181241880">(Nov 20 2019 at 19:44)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> Ok so this is how mentions work. Sry, I'm new to zulip.</p>



<a name="181242045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181242045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181242045">(Nov 20 2019 at 19:46)</a>:</h4>
<p><span class="user-mention" data-user-id="222148">@Felix Kohlgrüber</span> mainly because <code>regex</code> is a big dependency. We have it in the crate graph already (which is regrettable, I believe at least two of the three uses are completely unnecessary) , but core crates like <code>ra_ide_api</code> do not have this dependency</p>



<a name="181242215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/181242215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Felix Kohlgrüber <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#181242215">(Nov 20 2019 at 19:48)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> ok, sounds reasonable. I'll hand-roll my own ;-)</p>



<a name="186092674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/186092674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#186092674">(Jan 20 2020 at 11:21)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span>  I have several questions:</p>
<ol>
<li>
<p>You started from<code>Source { file_id: $file_id:expr, ast: $ast:expr }</code>  but later used </p>
<blockquote>
<p>replace <code>$ident:fragment</code> with <code>__search_pattern_ident</code> is <code> file_id: $file_id:expr</code>, should it be <code>$&lt;something&gt;:expr</code>?</p>
</blockquote>
</li>
<li>
<p>Is any way to sanitize  temporary names except of using <code>__search_pattern_&lt;ident1&gt;</code>, <code>__search_pattern_&lt;ident2&gt;</code> and etc?</p>
</li>
<li>I tried convert it to  macros declaration and parse, it works but I get <code>ast::TokenTree</code>, may be there is a way to convert  <code>ast::TokenTree</code> or use it during search?</li>
<li>If I need to write code to replace <code>$file_id:expr</code>  should it be done just by string functions or there is a better way,? </li>
<li>Do you have any example how to compare trees?</li>
</ol>



<a name="186279708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/186279708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#186279708">(Jan 22 2020 at 11:59)</a>:</h4>
<p>little bit more details for 3:</p>
<ol>
<li>convert a pattern to <code>macro_rules! { ({}) =&gt; ()  }</code></li>
<li>parse</li>
<li>replace  $file_id:expr by placeholders</li>
<li>convert back to string</li>
<li>parse again as expt</li>
</ol>
<p><span class="user-mention" data-user-id="133169">@matklad</span>  what do you think?</p>



<a name="186281274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/186281274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#186281274">(Jan 22 2020 at 12:23)</a>:</h4>
<p>Don’t have time to really dig into this right now, but I don’t think we<br>
need to parse anything as Macro here. I think just a text-based search for<br>
patterns should be enough for the initial impl, and should be easier to<br>
impl</p>



<a name="187350277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187350277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187350277">(Feb 04 2020 at 11:26)</a>:</h4>
<p>I've found that <code>expr_from_text</code> and <code>TextEdit</code> do not work together, because <code>expr_from_text</code> returns part of <code>"const C: () = {};"</code> with absolute offsets, so I need the full string back to make an edit. <span class="user-mention" data-user-id="133169">@matklad</span>  what do you think? I can just use <code>ast_from_text</code> same way as <code>expr_from_text</code> but it doesn't look right, or maybe there is a way to get relative offsets (<code>TextRange</code>)?</p>



<a name="187350571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187350571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187350571">(Feb 04 2020 at 11:31)</a>:</h4>
<p>Hm, good question!</p>
<p>Let me see if I can quicly fix <code>expr_from_text</code>, this seems like a footgun</p>



<a name="187353764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187353764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187353764">(Feb 04 2020 at 12:24)</a>:</h4>
<p><span class="user-mention" data-user-id="116925">@mikhail-m1</span> should be fixed by <a href="https://github.com/rust-analyzer/rust-analyzer/pull/3009" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/pull/3009">https://github.com/rust-analyzer/rust-analyzer/pull/3009</a></p>



<a name="187549388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187549388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187549388">(Feb 06 2020 at 13:56)</a>:</h4>
<p>I little bit stuck with </p>
<blockquote>
<p>Implement the driver, which visits all files in the current project and builds a SourceEdit</p>
</blockquote>
<p>could you send me an example? I've tried to do something like: <code>for krate in Crate::all(db)</code> but looks like it iterates over some files outside of workspace.</p>



<a name="187549477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187549477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187549477">(Feb 06 2020 at 13:57)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/ea9d18ba836a7228f7310e1bc77c0918f0191a42/crates/ra_ide/src/symbol_index.rs#L94-L98" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/ea9d18ba836a7228f7310e1bc77c0918f0191a42/crates/ra_ide/src/symbol_index.rs#L94-L98">https://github.com/rust-analyzer/rust-analyzer/blob/ea9d18ba836a7228f7310e1bc77c0918f0191a42/crates/ra_ide/src/symbol_index.rs#L94-L98</a></p>
<p>This is walks all local files for the purpose of index building</p>



<a name="187630288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187630288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187630288">(Feb 07 2020 at 11:07)</a>:</h4>
<p>Is any way to apply <code>SourceChange</code> without vs code?</p>



<a name="187630609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187630609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187630609">(Feb 07 2020 at 11:13)</a>:</h4>
<p>Nope, there's no code for that</p>



<a name="187630619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187630619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187630619">(Feb 07 2020 at 11:13)</a>:</h4>
<p>There's a way to apply text edit to a file though</p>



<a name="187721050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187721050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187721050">(Feb 08 2020 at 15:36)</a>:</h4>
<blockquote>
<p>There's a way to apply text edit to a file though</p>
</blockquote>
<p>next step, I have <code>SourceFileEdit</code> and it contains file_id, I can get file text and apply <code>TextEdit</code>  but I need to write it back and for it I need full path,  how can I get it? If I get it right, there are no full paths in Salsa, so I can do something similar to <code>ra_cli/src/analysis_bench.rs</code> or may be even build a map file_id -&gt; full path, but may be I've missed something.</p>



<a name="187757283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187757283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187757283">(Feb 09 2020 at 12:29)</a>:</h4>
<p>This generally should work like ra_analysis_cli.</p>



<a name="187757328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187757328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187757328">(Feb 09 2020 at 12:30)</a>:</h4>
<p>Wait, I am confusing myself</p>



<a name="187757349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187757349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187757349">(Feb 09 2020 at 12:31)</a>:</h4>
<p>I am thinking right now about a CLI tool for ssr, but I think the original plan was simply to expose this to VS Code? </p>
<p>Yeah, I guess we can do both a CLI and a VS Code action, and I would go with what's simpler. I <em>think</em> VS Code action might be simpler</p>



<a name="187765355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187765355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187765355">(Feb 09 2020 at 17:00)</a>:</h4>
<p>I created a working prototype for vscode only. It make changes in all files at once, but <code>undo</code> works only for current file. Rename's behavior is the same so I will leave it. I will try to clean it up and and create a PR soon. One more question, how should I call it? is <code>Ssr</code> enough or it's better to use <code>StructuralSearchReplace</code> everywhere?</p>



<a name="187766375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187766375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187766375">(Feb 09 2020 at 17:35)</a>:</h4>
<p>SSR is server-side rendering ;)</p>



<a name="187766538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187766538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187766538">(Feb 09 2020 at 17:40)</a>:</h4>
<p>I think structural search replace in IntelliJ existing before client side<br>
rendering was a thing :-)</p>



<a name="187766592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187766592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187766592">(Feb 09 2020 at 17:42)</a>:</h4>
<p>Well, I'd go better for <code>SSR</code> only if it is pervasive and we leave the comment on its meaning near the definition.</p>



<a name="187798952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187798952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187798952">(Feb 10 2020 at 09:12)</a>:</h4>
<blockquote>
<p>One more question, how should I call it? is Ssr enough or it's better to use StructuralSearchReplace everywhere?</p>
</blockquote>
<p>Internally I would prefer ssr, for all user-visible strings we should use structural search replace</p>



<a name="187931394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187931394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187931394">(Feb 11 2020 at 17:09)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span>  considering your <a href="https://github.com/rust-analyzer/rust-analyzer/pull/3099#issuecomment-584716007" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/pull/3099#issuecomment-584716007">comment</a>, have you put <code>$&lt;name&gt;:expr</code> to the second part as shown?  In this case it should be related how <code>expr_from_text</code> handle incorrect code.</p>



<a name="187931538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187931538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187931538">(Feb 11 2020 at 17:10)</a>:</h4>
<p>As I understand <code>expr_from_text</code> is never fails, but output for incorrect code may be weird.</p>



<a name="187931552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187931552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187931552">(Feb 11 2020 at 17:10)</a>:</h4>
<p>my bad, I indeed have done that</p>



<a name="187931613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187931613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187931613">(Feb 11 2020 at 17:11)</a>:</h4>
<p>I will check it later</p>



<a name="187931788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187931788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187931788">(Feb 11 2020 at 17:12)</a>:</h4>
<p>I've checked it, it actually works great if you use the right syntax <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="187932314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187932314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187932314">(Feb 11 2020 at 17:18)</a>:</h4>
<p>I mean I will check what is the output from <code>expr_from_text</code> for <code>foo(name:expr)</code></p>



<a name="187932757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187932757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187932757">(Feb 11 2020 at 17:22)</a>:</h4>
<p>Would you mind if I tweet about this work-in-progress today or tomorrow? </p>
<p>I've just tried it with the original <code>InFile</code> example, it works, and I am super excited!</p>



<a name="187945448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Structural%20Search%20Replace/near/187945448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mikhail-m1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Structural.20Search.20Replace.html#187945448">(Feb 11 2020 at 19:32)</a>:</h4>
<p>yeah, of course, feel free to share it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>